/**
 * 
 */
package com.swim.sys.web;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.swim.common.entity.CommonResults;
import com.swim.sys.service.SysUserRoleService;
import com.jeesite.common.config.Global;
import com.jeesite.common.web.BaseController;
import com.jeesite.modules.sys.utils.UserUtils;

/**
 * @description : 系统用户角色api控制层
 * @author      : 刘军武
 * @version     : 1.0  
 * @create      : 2020年3月11日 下午3:18:00
 **/
@Controller
@RequestMapping(value = "${adminPath}/sys/sysUserRole")
public class SysUserRoleController extends BaseController {
	
	@Autowired
	private SysUserRoleService sysUserRoleService;
	
	/**
	 * 根据UserCode查询该用户的角色RoleCode
	 * @return roleCode
	 */
	@ResponseBody
	@RequestMapping(value = "findRoleCodeByUserCode")
	public String findRoleCodeByUserCode(String userCode) {
		String roleCode = "";
		List<String> roleCodeList = sysUserRoleService.findRoleCodeByUserCode(userCode);
		roleCode = roleCodeList.get(0);
		return roleCode;
	}
	
	/**
	 * 用户登录时校验账号登录权限
	 * @param loginCode	用户账号
	 * @return CommonResults
	 */
	@ResponseBody
	@PostMapping(value = "checkLoginPermissions")
	public CommonResults checkLoginPermissions(String loginCode) {
		return sysUserRoleService.checkLoginPermissions(loginCode);
	}
	
	 /**
	  * 根据userName获取简单登录令牌
	  * @param userName 登录名(数据库中的 login_code字段)
	  * @return token
	  */
	@RequestMapping(value = "getLoginToken")
	@ResponseBody
	public String getLoginToken(String userName) {
		return renderResult(Global.TRUE, text("获取登录令牌成功！"), UserUtils.getSsoToken(userName));
	}
}